{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0c32843a",
   "metadata": {},
   "source": [
    "----\n",
    "- 记录人：vin\n",
    "- 时间：2021年11月29日\n",
    "- week14\n",
    "- 主要参考文档：[Python官方文档](https://www.python.org/)\n",
    "- [博客-函数](https://www.cnblogs.com/xuzhichao/p/11570285.html)\n",
    "\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13c18814",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "- 1、函数的定义\n",
    "- 2、如何使用函数\n",
    "- 3、函数的返回值\n",
    "- 4、使用注释改进文档\n",
    "- 5、传递任意数量的实参\n",
    "- 6、函数与模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a4a34fe7",
   "metadata": {},
   "source": [
    "## 函数的定义\n",
    "- def:定义函数的关键字\n",
    "- flb：函数名\n",
    "- (n)：定义函数的参数\n",
    "### 定义函数：\n",
    "- 1. 写def： def 定义函数的第一步\n",
    "- 2. 写定义函数的名称： def function_name 定义函数名称\n",
    "  - function_name 遵循变量名称定义的规则 （只能用字母、数字、下划线。第一个字符不能是数字。）\n",
    "- 3. 函数名称后加上“（）：”   ： def function_name() ===> f(x) = 2x \n",
    "\n",
    "### 书写函数体：\n",
    "- 1. 书写函数的注释\n",
    "- 2. 书写函数的具体操作（函数体）\n",
    "- 3. 注意：函数也是需要有 tab 键的间距\n",
    "\n",
    "### 使用函数（函数的调用）\n",
    "- 1. function_name()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b7252638",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:20:40.735429Z",
     "start_time": "2021-11-29T02:20:40.719624Z"
    }
   },
   "outputs": [],
   "source": [
    "def fib(n):    # write Fibonacci series up to n\n",
    "     \"\"\"Print a Fibonacci series up to n.\"\"\"\n",
    "     a, b = 0, 1\n",
    "     while a < n:\n",
    "         print(a, end=' ')\n",
    "         a, b = b, a+b\n",
    "     print()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "6fd36510",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:38:20.424841Z",
     "start_time": "2021-11-29T02:38:20.407901Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function fib in module __main__:\n",
      "\n",
      "fib(n)\n",
      "    Print a Fibonacci series up to n.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(fib)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "0a2bc7a3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:39:34.143762Z",
     "start_time": "2021-11-29T02:39:34.127744Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 1 2 3 5 8 \n"
     ]
    }
   ],
   "source": [
    "fib(10)  # 前两个数字相加等于后个数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "edd20379",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:39:13.379370Z",
     "start_time": "2021-11-29T02:39:13.370387Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 1 2 3 5 8 13 21 34 55 89 \n"
     ]
    }
   ],
   "source": [
    "fib(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "19e77d1c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:03:01.536852Z",
     "start_time": "2021-11-29T03:03:01.532851Z"
    }
   },
   "outputs": [],
   "source": [
    "## 尝试：写一个实现 hello world 的函数\n",
    "def hello():\n",
    "    \"\"\"打印hello world\"\"\"\n",
    "    print(\"hello world~\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "00527094",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:03:02.160383Z",
     "start_time": "2021-11-29T03:03:02.152105Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world~\n"
     ]
    }
   ],
   "source": [
    "hello()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b771be9",
   "metadata": {},
   "source": [
    "---\n",
    "- 下面的方法太重复了，主要原因是没有对重复功能的代码块有特殊的定义（如：名称，注释等）\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "29ba668b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:40:56.991450Z",
     "start_time": "2021-11-29T02:40:52.268902Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:bijlhdkjsl\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'i'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels = set('aeiou')\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = vowels.intersection(set(word))\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "003bfbe5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:42:07.380405Z",
     "start_time": "2021-11-29T02:41:55.732247Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:aeddioudhskaaecv\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'a', 'e', 'i', 'o', 'u'}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels = set('aeiou')\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = vowels.intersection(set(word))\n",
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86789628",
   "metadata": {},
   "source": [
    "---\n",
    "- 以下使用函数可减少操作，提高效率\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88d1647f",
   "metadata": {},
   "source": [
    "## 如何使用函数（课本实践p149）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "be8f5a4d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:49:53.111192Z",
     "start_time": "2021-11-29T02:49:53.091192Z"
    }
   },
   "outputs": [],
   "source": [
    "# 定义一个名字叫“search4vowels”函数\n",
    "def search4vowels(word):\n",
    "    \"\"\"\n",
    "    打印文本中出现的元音字母\n",
    "    请输入您想要查询的文本内容\n",
    "    \"\"\"\n",
    "    vowels = set('aeiou')\n",
    "#    word = input(\"Provide a word to search for vowels:\")\n",
    "    found = vowels.intersection(set(word))  # 交际运算\n",
    "    print(found)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "824f252d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:49:53.536363Z",
     "start_time": "2021-11-29T02:49:53.516733Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function search4vowels in module __main__:\n",
      "\n",
      "search4vowels(word)\n",
      "    打印文本中出现的元音字母\n",
      "    请输入您想要查询的文本内容\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(search4vowels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "229a2980",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:49:54.079744Z",
     "start_time": "2021-11-29T02:49:54.064746Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'a', 'i', 'o', 'u', 'e'}\n"
     ]
    }
   ],
   "source": [
    "search4vowels(\"aeddioudhskaaecv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "7837d2d7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T02:50:58.612550Z",
     "start_time": "2021-11-29T02:50:58.596531Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'i'}\n"
     ]
    }
   ],
   "source": [
    "search4vowels(\"bijlhdkjsl\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ff449ea",
   "metadata": {},
   "source": [
    "### 函数存在的意义\n",
    "- 1. 可以通过调用函数的方式实现某些功能，使用人不需要考虑函数代码内容\n",
    "- 2. 节省时间，提升应用的效率\n",
    "- 3. 函数一旦定义就可按照一定的规则重复使用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e75cca9",
   "metadata": {},
   "source": [
    "## 函数的参数\n",
    "* <font style=\"color:red\"> 注意：函数的参数可以没有.如果有参数，则如下（分为形式参数和实际参数）：</font>\n",
    "- 1. 形式参数（形参）\n",
    "  - 在定义过程中，函数的参数为形式参数\n",
    "  - 形式参数是虚拟的，不占用空间的\n",
    "- 2. 实际参数（实参）\n",
    "  - 调用函数过程中，函数的参数为实际参数\n",
    "  - 调用函数时，形式参数被分配空间，成为实际参数并应用起来"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "7885499e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:14:55.446747Z",
     "start_time": "2021-11-29T03:14:55.439747Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world~\n"
     ]
    }
   ],
   "source": [
    "# 函数是可以没有参数的\n",
    "hello()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "d97d7c61",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:17:29.902541Z",
     "start_time": "2021-11-29T03:17:29.888971Z"
    }
   },
   "outputs": [],
   "source": [
    "# 定义函数\n",
    "def greet_user(username):    \n",
    "     \"\"\"显示简单的问候语,输入你的名字\"\"\"    \n",
    "     print(\"hello,\"+username.title()+\"!\")          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "55103ea1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:17:30.464122Z",
     "start_time": "2021-11-29T03:17:30.455961Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello,Vin!\n"
     ]
    }
   ],
   "source": [
    "# 调用函数： username = “vin”\n",
    "greet_user(\"vin\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "161438c1",
   "metadata": {},
   "source": [
    "### 当参数不止一个时：\n",
    "- 1. 位置参数（positional argument）\n",
    "- [位置参数](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values)\n",
    "  - （1）形式参数有多个值，如果实际参数直接赋值，要按照形式参数的先后顺序,这种方式称：位置参数赋值\n",
    "  - （2）在调用函数过程中需要考虑如下：\n",
    "      - 考虑位置\n",
    "      - 考虑个数\n",
    "- 2. [关键字参数](https://docs.python.org/3/tutorial/controlflow.html#keyword-arguments)\n",
    "  - （1）在调用函数时使用，我们直接在实参中 用赋值的方式去定义形参\n",
    "  - （2）不需要考虑顺序，因为赋值已经确定了形参的值\n",
    "- 3. 默认参数\n",
    "  - （1）默认参数写在 形式参数中(预计有大量的调用会使用到的值，可以预先设置)\n",
    "  - （2）默认参数存在话，实际调用过程中可以省略赋值的过程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "300df8e1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:32:52.545532Z",
     "start_time": "2021-11-29T03:32:52.536515Z"
    }
   },
   "outputs": [],
   "source": [
    "# 请注意，有两个参数\n",
    "# 描述宠物信息\n",
    "def describe_pet(animal_type,pet_name):\n",
    "    \"\"\"显示宠物信息\"\"\"\n",
    "    print(\"\\nI have a \" + animal_type + \".\")\n",
    "    print(\"My\" + animal_type + \"'s name is \"+pet_name.title() + \".\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "ddef0f33",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:32:58.977512Z",
     "start_time": "2021-11-29T03:32:58.961510Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "I have a dog.\n",
      "Mydog's name is 小土狗.\n"
     ]
    }
   ],
   "source": [
    "# 调用宠物信息\n",
    "describe_pet(\"dog\",\"小土狗\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "3f419119",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:25:54.046880Z",
     "start_time": "2021-11-29T03:25:54.027591Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "I have a 小土狗.\n",
      "My小土狗's name is Dog.\n"
     ]
    }
   ],
   "source": [
    "describe_pet(\"小土狗\",\"dog\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "3a08edc7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:30:05.983899Z",
     "start_time": "2021-11-29T03:30:05.967819Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "I have a dog.\n",
      "Mydog's name is 小土狗.\n"
     ]
    }
   ],
   "source": [
    "# 关键字参数\n",
    "describe_pet(animal_type=\"dog\",pet_name=\"小土狗\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "c6d51c43",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:30:46.817047Z",
     "start_time": "2021-11-29T03:30:46.811028Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "I have a dog.\n",
      "Mydog's name is 小土狗.\n"
     ]
    }
   ],
   "source": [
    "describe_pet(pet_name=\"小土狗\",animal_type=\"dog\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "49f47ac6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:37:37.694966Z",
     "start_time": "2021-11-29T03:37:37.685987Z"
    }
   },
   "outputs": [],
   "source": [
    "# 默认参数（写在形式参数中的）\n",
    "def describe_pet(pet_name,animal_type=\"dog\"):\n",
    "    \"\"\"显示宠物信息，animal_typ 的默认值为 'dog'\"\"\"\n",
    "    print(\"\\nI have a \" + animal_type + \".\")\n",
    "    print(\"My\" + animal_type + \"'s name is \"+pet_name.title() + \".\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "31d59e8f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:37:38.210917Z",
     "start_time": "2021-11-29T03:37:38.202915Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "I have a dog.\n",
      "Mydog's name is 小土狗.\n"
     ]
    }
   ],
   "source": [
    "describe_pet(\"小土狗\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "c56871cc",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:38:02.231217Z",
     "start_time": "2021-11-29T03:38:02.216199Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "I have a cat.\n",
      "Mycat's name is 小土猫.\n"
     ]
    }
   ],
   "source": [
    "describe_pet(\"小土猫\",\"cat\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3408e324",
   "metadata": {},
   "source": [
    "---\n",
    "* 实操和注意（参数部分）\n",
    "- 1. 如果想，关键字参数 和 位置参数 共同使用\n",
    "   - positional argument follows keyword argument（位置参数需要放在关键字参数前面）\n",
    "   - 关键字参数放在末尾（均为关键字，不考虑顺序）\n",
    "- 2.默认参数\n",
    "   - non-default argument follows default argument(非默认参数许要放在默认参数后面)\n",
    "   - 默认参数放在末尾（均为默认参数，不考虑顺序）\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "0696e1f3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:50:12.556945Z",
     "start_time": "2021-11-29T03:50:12.538308Z"
    }
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (<ipython-input-97-d219ba831f78>, line 6)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-97-d219ba831f78>\"\u001b[1;36m, line \u001b[1;32m6\u001b[0m\n\u001b[1;33m    func_test(x=1,2)      #？\u001b[0m\n\u001b[1;37m                  ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "#eg1\n",
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    \n",
    "func_test(x=1,2)      #？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "4c3b183d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:50:13.139316Z",
     "start_time": "2021-11-29T03:50:13.122313Z"
    }
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "func_test() got multiple values for argument 'x'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-98-a0faf4a9ed0b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      4\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mfunc_test\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m      \u001b[1;31m#？\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: func_test() got multiple values for argument 'x'"
     ]
    }
   ],
   "source": [
    "#eg1\n",
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    \n",
    "func_test(2,x=1)      #？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "2dad7d3c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:50:13.748875Z",
     "start_time": "2021-11-29T03:50:13.731285Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "#eg1\n",
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    \n",
    "func_test(2,y=1)      #？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "aa3f43c5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:50:24.389971Z",
     "start_time": "2021-11-29T03:50:24.373087Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "1\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "#eg2\n",
    "def func_test(x,y,z):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    print(z)\n",
    "    \n",
    "func_test(2,y=1,z=3)      #？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "38a03183",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:50:38.194982Z",
     "start_time": "2021-11-29T03:50:38.175980Z"
    }
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (<ipython-input-102-6524ae3721ca>, line 7)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-102-6524ae3721ca>\"\u001b[1;36m, line \u001b[1;32m7\u001b[0m\n\u001b[1;33m    func_test(2,y=1,3)      #？\u001b[0m\n\u001b[1;37m                    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "#eg2\n",
    "def func_test(x,y,z):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    print(z)\n",
    "    \n",
    "func_test(2,y=1,3)      #？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "de435424",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:53:17.161870Z",
     "start_time": "2021-11-29T03:53:17.151868Z"
    }
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "non-default argument follows default argument (<ipython-input-103-5f5c8c259261>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-103-5f5c8c259261>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    def func_test(x,y=4,z):\u001b[0m\n\u001b[1;37m                  ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m non-default argument follows default argument\n"
     ]
    }
   ],
   "source": [
    "#eg3\n",
    "def func_test(x,y=4,z):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    print(z)\n",
    "    \n",
    "func_test(2,1,3)      #？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "985c03b3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-29T03:54:14.584815Z",
     "start_time": "2021-11-29T03:54:14.567782Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "3\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "#eg3\n",
    "def func_test(x,z,y=3):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    print(z)\n",
    "    \n",
    "func_test(2,1,3)      #？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2fb90b4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
